import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zengfh
 * @version 1.0
 * date 2017/10/31 14:41
 */
public class MyThread implements Runnable{
    
    private static final Logger LOGGER = LoggerFactory.getLogger(MyThread.class);
    
    private static final CountDownLatch COUNT_DOWN_LATCH = new CountDownLatch(1000);
    
    private String name;
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public MyThread(String name){
        this.name = name;
    }
    @Override
    public void run() {
        //System.out.println(Thread.currentThread().getName() + "开始执行" + this.name);
        try {
            Thread.sleep(5000);
            System.out.println(Thread.currentThread().getName() + "开始执行" + this.name);
            COUNT_DOWN_LATCH.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        COUNT_DOWN_LATCH.countDown();
        
    }
    
    public static void main(String[] args){
        //ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
        ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1000);
        for (int i = 0; i < 1000; i++) {
            cachedThreadPool.execute(new MyThread("任务" + (i + 1)));

        }
    }
}
